package com.dhb.pattern.strategy;

import com.dhb.pattern.strategy.promotion.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 功能描述：结合单例和工厂模式，创建促销类
 * 创建人：citymoon
 * 创建日期：2019/5/21
 */
public class PromotionStrategyFactory {
    private static Map<String, PromotionStrategy> PROMOTION_STRATEGY_MAP =
            new HashMap<String, PromotionStrategy>();
    static {
        PROMOTION_STRATEGY_MAP.put(PromotionKey.PROMOTION_GROUPBUY, new GroupbuyStrategy());
        PROMOTION_STRATEGY_MAP.put(PromotionKey.PROMOTION_CASHBACK, new CashbackStrategy());
        PROMOTION_STRATEGY_MAP.put(PromotionKey.PROMOTION_COUPON, new CouponStrategy());
    }
    private static final PromotionStrategy NON_PROMOTION = new EmptyStrategy();

    private PromotionStrategyFactory(){}

    public static PromotionStrategy getPromotionStrategy(String promotionKey){
        PromotionStrategy promotionStrategy = PROMOTION_STRATEGY_MAP.get(promotionKey);
        return promotionStrategy == null? NON_PROMOTION : promotionStrategy;
    }
}
